package com.doumi.biz.qadev.api.testcase.commonfilter;

import com.doumi.biz.qadev.api.methods.OperationRedis;
import com.doumi.biz.qadev.api.testcase.RequestTemplate;
import io.restassured.path.json.JsonPath;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by YDZ on 2019/11/30.
 */
public class CommonFilterVacantNumber {

    /**
     * 手机号码中拨打5次，手机号前几位为虚拟号码判断
     */
    private RequestTemplate requestTemplate = new RequestTemplate();
    private OperationRedis operationRedis = new OperationRedis();
    private static List<String> cuIds = new ArrayList<>();
    HashMap hashMap = new HashMap();

    //redis初始化数据
    @BeforeClass(description = "初始化redis数据")
    public  void operationData(){
        String filenanme = "src/source/redisfile/filter-vacontMobile.csv";
        String mothodname = "vacontMobile";
        cuIds = operationRedis.readCsvoperationRedis(filenanme,mothodname,6);
        hashMap.put("companyId","11111");
        hashMap.put("buserId",321245);
    }
    @Test(description = "用户信息中手机号为被标记为空号的用户，只有242110007，242110006是正常用户信息，预期返回两个用户")
    public void checkMobileIsVacontNumberOrCalledTimesGreaterFive(){
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i <cuIds.size()-1;  i++) {
            sb.append(cuIds.get(i).trim()).append(",");
        }
        sb.append(cuIds.get(cuIds.size()-1).trim());
        sb.append("]");
        hashMap.put("cuIds",sb.toString());
        hashMap.put("businessType","1");
        hashMap.put("contactStatus",1);
        JsonPath jsonPath =requestTemplate.postCommonFilter(hashMap);
        List resurlt = jsonPath.getList("data");
        String msg = jsonPath.getString("msg");
        Assert.assertEquals(resurlt.size(),1);
        Assert.assertEquals(String.valueOf(resurlt.get(0)),String.valueOf(242110006));
        Assert.assertEquals(msg,"success");
    }
    //新增接口修改
    @Test(description = "请求接口mobile/check,参数中的用户手机号13188979986为空号，预期结果返回数据手机号号为：15811438030")
    public void mobileCheck(){
        HashMap hashMap = new HashMap();
        hashMap.put("mobiles","[15811438030,13188979986]");
        hashMap.put("requestId","86957854");
        JsonPath jsonPath =requestTemplate.getMobileCheck(hashMap);
        Assert.assertEquals(jsonPath.getString("data[0]"),"15811438030");
    }
    //删除数据
    @AfterClass(description = "删除出入掉的数据，避免影响其他测试")
    public void removeData(){
//        operationRedis.removeRedis(cuIds);
//        operationRedis.clearRedisCallTimes();//清空特殊的值
//      String s=  operationRedis.getValue();
//        System.out.println(s);

    }

}
